
public class AnalyzerThread extends Thread
{
	MultiThreadEnv my_delegate;
	private boolean still_retrieving = true;
	public void run()
	{
		while (still_retrieving)
		{
			PageObject my_values;
			try
			{
				my_delegate.analyzer_lock.lock();
					my_values = my_delegate.getHashArrayQueue().poll();
				if (my_values != null)
				{
					try
					{
						StringBuilder output_string = new StringBuilder("<html>");
						output_string.append("<br/>");
						output_string.append("<br/>");
						output_string.append("Parsed:" + my_values.getUrl());
						output_string.append("<br/>");
						output_string.append("Pages Retrieved: " + (my_values.getPageNumber() + 1));
						output_string.append("<br/>");
						output_string.append("Average words per page: " + (my_values.getTotalWordsReadAtTime() / (my_values.getPageNumber() + 1) ));
						output_string.append("<br/>");
						output_string.append("Average URLs per page: " + (my_values.getTotalURLCount() / (my_values.getPageNumber() + 1) ));
						output_string.append("<br/>");
						output_string.append("<table><tr>");
						output_string.append("<td>Keyword</td><td>AverageHitsPerPage</td><td>TotalHits</td></tr>");
						
						for (int i = 0; i < my_values.getKeywordArray().size();i++)
						{
							StringBuilder output = new StringBuilder("<tr><td>");
							output.append(my_values.getKeywordArray().get(i));
							output.append("</td>");
							output.append("<td>");
							output.append(my_values.getKeywordMap().get(my_values.getKeywordArray().get(i).hashCode()) / (my_values.getPageNumber() + 1));
							output.append("</td>");
							output.append("<td>");
							output.append(my_values.getKeywordMap().get(my_values.getKeywordArray().get(i).hashCode()));
							output.append("</td></tr>");
							
							output_string.append(output.toString());
							
						}
						output_string.append("</table>");
						output_string.append("<br/>");
						output_string.append("Page limit: " + my_delegate.getParsePageLimit());
						output_string.append("<br/>");
						output_string.append("Average parse time per page: " + my_values.getAverageParseTime() / (my_values.getPageNumber() + 1) + "ms");
						output_string.append("<br/>");
						output_string.append("Total running time: " + my_values.getRunningTime() / 1000 + "sec.");
						output_string.append("<br/>");
						my_delegate.handleOutputString(output_string.toString());
						output_string.append("<br/>");
						output_string.append("</html>");
					} catch(Exception the_e){}
				}
				my_delegate.analyzer_lock.unlock();	
			}
			catch (Exception the_e){
			}
		}
	}
	public void setDelegate(MultiThreadEnv the_delegate)
	{
		my_delegate = the_delegate;
	}
	public void killRetrieve()
	{
		still_retrieving = false;
	}
}
